<template>
  <div class="app-container">
    <el-form :model="searchForm" label-width="110px" @keyup.enter.native="search()">
      <el-row>
        <el-col class="professions">
          <el-form-item label="所属专业" size="small">
            <el-select v-model="searchForm.professions" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in parentProfessionList"
                :key="item.professionId"
                :label="item.professionName"
                :value="item.professionName">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!--<el-col class="other">-->
        <!--<el-form-item label="所属团队" size="small">-->
        <!--<el-input v-model="searchForm.teamName"></el-input>-->
        <!--</el-form-item>-->
        <!--</el-col>-->
        <el-col class="other">
          <el-form-item label="项目名称" size="small">
            <el-input v-model="searchForm.projectName"></el-input>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="合同编号" size="small">
            <el-input v-model="searchForm.contractCode"></el-input>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="性质" size="small" class="item-inline">
            <el-select v-model="searchForm.property" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.propertyList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="合作性质" size="small">
            <el-select v-model="searchForm.leadPerson" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.leadPersonList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="有无中标通知书" size="small" class="item-inline">
            <el-select v-model="searchForm.isTenderBook" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.isTenderBookList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="有无合同文件" size="small" class="item-inline">
            <el-select v-model="searchForm.isContract" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.isTenderBookList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="searchBtn">
          <el-form-item size="small">
            <el-button type="primary" icon="el-icon-search" @click="search()">搜索</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="table-btn">
      <el-button type="primary" size="small" icon="el-icon-plus" @click="addTeam()"
                 v-if="roleType!==6 && roleType!==13">添加
      </el-button>
      <el-dialog :title="dialogTitle" :visible.sync="outerVisible" width="1250px" @close="closeOuterVisible">
        <el-form ref="teamRow" :rules="rules" :model="teamRow" label-width="110px">
          <el-form-item prop="projectName" label="项目名称" size="small">
            <el-input type="text" v-model="teamRow.projectName"></el-input>
          </el-form-item>
          <el-row>
            <el-col class="dialog-line">
              <el-form-item prop="teamName" label="所属团队" size="small">
                <el-autocomplete
                  v-model="teamRow.teamName"
                  :fetch-suggestions="querySearchTeam"
                  @select="handleSelectTeam"
                  placeholder="请输入内容"
                >
                </el-autocomplete>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="partyA" label="甲方单位" size="small">
                <el-input type="text" v-model="teamRow.partyA"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="contractCode" label="合同编号" size="small">
                <el-input type="text" v-model="teamRow.contractCode" @blur="contractBlur"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item label="性质" size="small" class="item-inline">
                <el-select v-model="teamRow.property" placeholder="请选择">
                  <el-option
                    v-for="item in global.propertyList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col>
              <el-form-item prop="address" label="项目所属地" size="small">
                <area-cascader v-model="teamRow.addressId" v-if="isAddress" placeholder="请选择省市" :data="pca"
                               @change="addressChange()" class="item-inline"></area-cascader>
                <el-input type="text" v-model="teamRow.address" placeholder="请填写项目所属地" style="width: 890px"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item label="项目负责人" size="small">
                <el-input type="text" v-model="teamRow.projectLeader"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="principalContact" label="联系方式" size="small">
                <el-input type="text" v-model="teamRow.principalContact"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="signDate" label="签订日期" size="small">
                <el-date-picker
                  v-model="teamRow.signDate"
                  type="date"
                  value-format="timestamp"
                  placeholder="选择日期"
                  style="width: 190px"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="projectScale" label="项目规模" size="small">
                <el-input type="text" v-model="teamRow.projectScale"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="contractAmount" label="合同金额" size="small">
                <el-input type="number" v-model.number="teamRow.contractAmount">
                  <span slot="suffix">万元</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item label="造价" size="small">
                <el-input type="number" v-model.number="teamRow.projectCost">
                  <span slot="suffix">万元</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="projectStage" label="项目阶段" size="small">
                <el-select v-model="teamRow.projectStage" placeholder="请选择">
                  <el-option
                    v-for="item in global.projectStageList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="leadingDiscipline" label="主导专业" size="small">
                <el-select v-model="teamRow.leadingDiscipline" placeholder="请选择">
                  <el-option
                    v-for="item in parentProfessionList"
                    :key="item.professionId"
                    :label="item.professionName"
                    :value="item.professionId">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="invoiceRate" label="设计税率" size="small">
                <el-select v-model="teamRow.invoiceRate" placeholder="请选择">
                  <el-option
                    v-for="item in global.invoiceRateList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="projectRate" label="工程税率" size="small">
                <el-select v-model="teamRow.projectRate" placeholder="请选择">
                  <el-option
                    v-for="item in global.projectRateList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item v-if="roleType===0||roleType===1||roleType===5" label="其他费率" size="small">
                <el-input type="number" v-model.number="teamRow.other">
                  <span slot="suffix">%</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item v-if="roleType===0||roleType===1||roleType===5" prop="epcRate" label="EPC税率" size="small">
                <el-select v-model="teamRow.epcRate" placeholder="请选择">
                  <el-option
                    v-for="item in global.invoiceRateList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item v-if="roleType===0||roleType===1||roleType===5" label="管理费" size="small">
                <el-input type="number" v-model.number="teamRow.managementFee">
                  <span slot="suffix">%</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item v-if="roleType===0||roleType===1||roleType===5" label="签字费" size="small">
                <el-input type="number" v-model.number="teamRow.signature">
                  <span slot="suffix">%</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item v-if="roleType===0||roleType===1||roleType===5" label="审核费" size="small">
                <el-input type="number" v-model.number="teamRow.audit">
                  <span slot="suffix">%</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item label="资料上传负责人" size="small">
                <el-input type="text" v-model="teamRow.updatePrincipal"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="projectScale" label="原件归档处" size="small">
                <el-input type="text" v-model="teamRow.originalArchive"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item label="合作性质" size="small">
                <el-select v-model="teamRow.leadPerson" placeholder="请选择">
                  <el-option
                    v-for="item in global.leadPersonList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="阶段进度" size="small">
            <el-button type="primary" icon="el-icon-plus" @click="addpp()"></el-button>
          </el-form-item>
          <el-row v-for="(item,index) in pp">
            <el-col class="other">
              <el-form-item label="百分比" size="small">
                <el-input type="number" v-model.number="item.percentage" @input="percentageChange(item,index)">
                  <span slot="suffix">%</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="other">
              <el-form-item label="金额" size="small">
                <el-input type="number" v-model.number="item.price">
                  <span slot="suffix">万元</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="other">
              <el-form-item label="节点" size="small">
                <el-input type="text" v-model="item.node"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="searchBtn">
              <el-form-item size="small">
                <el-button type="danger" size="small" icon="el-icon-minus" @click="delpp(index)"></el-button>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="有无项目子项目" size="small">
            <el-switch
              v-model="teamRow.isProject"
              active-color="#13ce66"
              inactive-color="#ff4949"
              :active-value=1
              :inactive-value=0
              :disabled="isProjectDisabled"
            >
            </el-switch>
          </el-form-item>
          <el-row>
            <el-col class="dialog-line">
              <el-form-item prop="balance" v-if="teamRow.isProject" label="结算差额" size="small">
                <el-input type="number" v-model.number="teamRow.balance">
                  <span slot="suffix">万元</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="dialog-line">
              <el-form-item prop="isAdd" v-if="teamRow.isProject" label="形式" size="small">
                <el-radio-group v-model="teamRow.isAdd">
                  <el-radio :label="1">增</el-radio>
                  <el-radio :label="0">减</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col>
              <el-form-item label="子备注" v-if="teamRow.isProject" size="small">
                <el-input type="textarea" v-model="teamRow.childRemark"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="所属专业" size="small">
            <el-checkbox-group v-for="(profession,index) in professionList" v-model="teamRow.parentProfessions">
              <el-checkbox :label="profession.professionName" :key="profession.professionName"
              >
                {{profession.professionName}}
              </el-checkbox>
              <el-checkbox-group v-model="teamRow.childProfessions"
                                 @change="handleprofessionChange(index,profession)">
                <el-checkbox v-for="item in profession.getParent" :label="item.professionId"
                             :key="item.professionId">
                  {{item.professionName}}
                </el-checkbox>
              </el-checkbox-group>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="招标公告" size="small">
            <input type="file" ref='tenderNoticeFile' @change="getTenderNoticeFile($event)">
          </el-form-item>
          <el-form-item label="投标文件" size="small">
            <input type="file" ref='biddingDocumentFile' @change="getBiddingDocumentFile($event)">
          </el-form-item>
          <el-form-item label="中标通知书" size="small">
            <input type="file" ref='letterFile' @change="getLetterFile($event)">
          </el-form-item>
          <el-form-item prop="contractFile" label="合同上传" size="small">
            <input type="file" ref='contractFile' @change="getFile($event)">
          </el-form-item>
          <el-form-item label="备注说明" size="small">
            <el-input type="textarea" v-model="teamRow.remark"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="warning" size="small"  @click="submitForm('teamRow')" v-no-more-click :disabled="isContractCode">确定
          </el-button>
          <el-button size="small" @click="outerVisible = false">取消</el-button>
        </div>
      </el-dialog>
      <a target="_blank"
         :href="`/project/export?${encodeURI(exportUrl)}`" v-if="roleType!==6 && roleType!==13">
        <el-button type="warning" size="small" icon="el-icon-upload2">
          导出
        </el-button>
      </a>
    </div>
    <my-table
      :data="tableData"
      :col-configs="roleType===13?roleTypeConfigs:colConfigs"
      v-loading="listLoading"
      :page-num="pageNum"
      :page-size="pageSize"
      :table-type="tableType"
      :expand-all="expandAll"
      @fetchData="fetchData"
      @openVisible="openVisible"
    >
      <el-table-column
        slot="opt"
        fixed="right"
        label="操作"
        width="150"
        v-if="roleType!==6 && roleType!==13"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="editProfession(scope.row.professions)">查看专业</el-button>
          <!--<el-button-->
          <!--@click.native.prevent="editSchedule(scope.row)"-->
          <!--type="text"-->
          <!--size="small">-->
          <!--资料管理-->
          <!--</el-button>-->
          <!--<a target="_blank" v-if="scope.row.contractFile"-->
          <!--:href="GLOBAL.downloadUrl +'?filePath='+scope.row.contractFile">下载</a>-->
          <el-button
            @click.native.prevent="editTeam(scope.row.projectId)"
            type="text"
            size="small">
            修改
          </el-button>
          <el-popover
            placement="top"
            width="160"
            :ref="`popover-${scope.$index}`"
          >
            <p>确定删除这条数据吗?</p>
            <div style="text-align: right; schedule: 0">
              <el-button size="mini" type="text" @click="$refs[`popover-${scope.$index}`].doClose()">取消</el-button>
              <el-button type="primary" size="mini" @click.native.prevent="deleteRow(scope)">确定</el-button>
            </div>
            <el-button type="text" size="small" slot="reference" v-popover:popover-${scope.$index}>删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </my-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    <el-dialog :title="scheduleTitle" :visible.sync="scheduleVisible" width="600px">
      <el-form ref="schedule" :rules="scheduleRules" :model="schedule" label-width="100px" class="formBorder">
        <el-form-item prop="phase" label="类型" size="small">
          <el-select v-model="schedule.phase" placeholder="请选择">
            <el-option
              v-for="item in GLOBAL.projectPhaseList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="projectName" label="项目名称" size="small">
          <el-input type="text" v-model="schedule.projectName" :disabled="true"></el-input>
        </el-form-item>
        <div v-if="schedule.phase === 1">
          <el-form-item label="文本图" size="small">
            <input type="file" ref='schemeText' @change="fileUpload($event,'schemeTextFile')">
          </el-form-item>
          <el-form-item label="CAD" size="small">
            <input type="file" ref='schemeCad' @change="fileUpload($event,'schemeCadFile')">
          </el-form-item>
          <el-form-item label="效果图" size="small">
            <input type="file" ref='schemeRendering' @change="fileUpload($event,'schemeRenderingFile')">
          </el-form-item>
          <el-form-item label="前期资料" size="small">
            <input type="file" ref='schemeProphaseData' @change="fileUpload($event,'schemeProphaseDataFile')">
          </el-form-item>
          <el-form-item label="批复文件" size="small">
            <input type="file" ref='schemeApprovalFile' @change="fileUpload($event,'schemeApprovalFileFile')">
          </el-form-item>
        </div>
        <div v-if="schedule.phase === 2">
          <el-form-item label="文本图" size="small">
            <input type="file" ref='designText' @change="fileUpload($event,'designTextFile')">
          </el-form-item>
          <el-form-item label="CAD" size="small">
            <input type="file" ref='designCad' @change="fileUpload($event,'designCadFile')">
          </el-form-item>
          <el-form-item label="会议纪要" size="small">
            <input type="file" ref='designMinutesMeeting' @change="fileUpload($event,'designMinutesMeetingFile')">
          </el-form-item>
          <el-form-item label="批复文件" size="small">
            <input type="file" ref='designApprovalFile' @change="fileUpload($event,'designApprovalFileFile')">
          </el-form-item>
        </div>
        <div v-if="schedule.phase === 3">
          <el-form-item label="内部审校意见" size="small">
            <input type="file" ref='drawingReviewOpinion' @change="fileUpload($event,'drawingReviewOpinionFile')">
          </el-form-item>
          <el-form-item label="CAD(终稿)" size="small">
            <input type="file" ref='drawingCad' @change="fileUpload($event,'drawingCadFile')">
          </el-form-item>
          <el-form-item label="DWF审查合格章" size="small">
            <input type="file" ref='drawingDwfText' @change="fileUpload($event,'drawingDwfTextFile')">
          </el-form-item>
          <el-form-item label="结构模型" size="small">
            <input type="file" ref='drawingStructuralModel' @change="fileUpload($event,'drawingStructuralModelFile')">
          </el-form-item>
          <el-form-item label="各类计算机书" size="small">
            <input type="file" ref='drawingComputerBook' @change="fileUpload($event,'drawingComputerBookFile')">
          </el-form-item>
          <el-form-item label="违反强条数量" size="small">
            <input type="file" ref='drawingViolationQuantity'
                   @change="fileUpload($event,'drawingViolationQuantityFile')">
          </el-form-item>
          <el-form-item label="审查意见及回复" size="small">
            <input type="file" ref='drawingReviewCommentsResponses'
                   @change="fileUpload($event,'drawingReviewCommentsResponsesFile')">
          </el-form-item>
          <el-form-item label="审查合格书" size="small">
            <input type="file" ref='drawingReviewQualifiedBook'
                   @change="fileUpload($event,'drawingReviewQualifiedBookFile')">
          </el-form-item>
        </div>
        <div v-if="schedule.phase === 4">
          <el-form-item label="验收报告" size="small">
            <input type="file" ref='completionAcceptanceReport'
                   @change="fileUpload($event,'completionAcceptanceReportFile')">
          </el-form-item>
        </div>
        <el-form-item prop="remark" label="备注说明" size="small">
          <el-input type="textarea" v-model="schedule.remark"></el-input>
        </el-form-item>
        <el-form-item size="small">
          <el-button type="warning" size="small" @click="submitSchedule('schedule')">
            {{scheduleBtn}}
          </el-button>
        </el-form-item>
      </el-form>
      <!--
      <my-table
        :data="scheduleData"
        :col-configs="scheduleConfigs"
        v-loading="scheduleLoading"
        :height="200"
      >
        <el-table-column
          slot="scheduleOpt"
          fixed="right"
          label="操作"
          width="150">
          <template slot-scope="scope">
            <el-popover
              placement="top"
              width="160"
              :ref="`schedule-${scope.$index}`"
            >
              <p>确定删除这条数据吗?</p>
              <div style="text-align: right; schedule: 0">
                <el-button size="mini" type="text" @click="$refs[`schedule-${scope.$index}`].doClose()">取消</el-button>
                <el-button type="primary" size="mini" @click.native.prevent="deleteSchedule(scope)">确定</el-button>
              </div>
              <el-button type="text" size="small" slot="reference" v-popover:schedule-${scope.$index}>删除</el-button>
            </el-popover>
          </template>
        </el-table-column>
      </my-table>
      -->
    </el-dialog>
    <el-dialog title="所属专业" :visible.sync="professionVisible" width="1100px">
      <el-form>
        <el-form-item size="small">
          <el-checkbox-group v-for="(profession,index) in professionList" v-model="teamRow.parentProfessions">
            <el-checkbox :label="profession.professionName" :key="profession.professionName"
            >
              {{profession.professionName}}
            </el-checkbox>
            <el-checkbox-group v-model="teamRow.childProfessions"
                               @change="handleprofessionChange(index,profession)">
              <el-checkbox v-for="item in profession.getParent" :label="item.professionId"
                           :key="item.professionId">
                {{item.professionName}}
              </el-checkbox>
            </el-checkbox-group>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog :title="imgMsg.label" :visible.sync="imgTableVisible" width="650px">
      <my-table
        :data="imgTableData"
        :col-configs="imgConfigs"
        v-loading="imgListLoading"
      >
        <el-table-column
          slot="imgOpt"
          fixed="right"
          label="操作"
          width="120">
          <template slot-scope="scope">
            <el-popover
              placement="top"
              width="160"
              :ref="`popover-imgTable${scope.$index}`"
            >
              <p>确定删除这条数据吗?</p>
              <div style="text-align: right; margin: 0">
                <el-button size="mini" type="text" @click="$refs[`popover-imgTable${scope.$index}`].doClose()">取消
                </el-button>
                <el-button type="primary" size="mini" @click.native.prevent="deleteImgTable(scope)">确定</el-button>
              </div>
              <el-button type="text" size="small" slot="reference" v-popover:popover-imgTable${scope.$index}>删除
              </el-button>
            </el-popover>
          </template>
        </el-table-column>
      </my-table>

    </el-dialog>
  </div>
</template>

<script>
  import {
    addProject,
    addProject1,
    addProjectInfo,
    findProjectById,
    findProjectInfoById,
    getListProject,
    getParentProfessionList,
    getProjectInfoList,
    getTypeByUseType,
    selectProfessions,
    selectTeam,
    updateProject,
    updateProject1,
    updateProjectInfo,
    updateProjectInfo1,
    findRepeatProject,
    getListInstitudeProject,
    getAttachList,
    delAttach
  } from '@/api/contractproject'
  import myTable from '@/components/myTable'
  import global from '@/components/global'

  import { AreaSelect } from 'vue-area-linkage'
  import { pca } from 'area-data'
  import { formatDate } from '@/utils/index'
  import { isvalidPhone } from '@/utils/validate'

  const filePath = {
    props: ['colConfig'],
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
      <span slot-scope="scope">
        <div>
         <a v-if="scope.row[colConfig.prop]" target="_blank" :href="GLOBAL.filePathUrl+ encodeURI(scope.row[colConfig.prop])">下载</a>
        </div>
      </span>
  </el-table-column>
  `
  }

  const signDate = {
    props: ['colConfig'],
    filters: {
      formatDate(time) {
        var date = new Date(time)
        return formatDate(date, 'yyyy-MM-dd')
      }
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
      <span slot-scope="scope">
        {{ scope.row[colConfig.prop] | formatDate }}
      </span>
  </el-table-column>
  `
  }

  const configs = {
    props: ['colConfig'],
    data() {
      return {
        projectId: '',
        infoId: '',
        prop: '',
        contractCode: '',
        projectName: '',
        signDate: '',
        precent: 0,
        progress: ''
      }
    },
    methods: {
      downloadFile(row, prop, column) {
        this.row = row
        this.column = column
        this.projectId = row.projectId
        this.infoId = row.infoId
        this.prop = prop
        this.contractCode = row.contractCode
        this.projectName = row.projectName
        this.signDate = row.signDate
        this.$refs.file.click()
      },
      upLoad(upLoad, params, callback1, callback2) {
        upLoad(params, function(progressEvent) { // 原生获取上传进度的事件
          if (progressEvent.lengthComputable) {
            // 属性lengthComputable主要表明总共需要完成的工作量和已经完成的工作是否可以被测量
            // 如果lengthComputable为false，就获取不到progressEvent.total和progressEvent.loaded
            callback1(progressEvent)
          }
        }).then(res => {
          callback2(res.data)
        }).catch(() => {
          this.$refs.file.value = ''
          this.progress = ''
        })
      },
      fileChanged() {
        const _this = this
        _this.progress = `${_this.row.projectId}${_this.column.id}`
        _this.precent = 0
        const params = new FormData()
        params.append('projectId', this.projectId)
        if (this.prop === 'file' || this.prop === 'letterFile' || this.prop === 'tenderNoticeFile' || this.prop === 'biddingDocumentFile') {
          params.append('contractCode', this.contractCode)
          params.append('projectName', this.projectName)
          if (this.signDate) {
            params.append('signDate', this.signDate)
          }
          params.append(this.prop, this.$refs.file.files[0])
          updateProject1(params).then(response => {
            _this.upLoad(updateProject, params, (res) => {
              const loaded = res.loaded
              const total = res.total
              _this.$nextTick(() => {
                _this.precent = (loaded / total) * 100
              })
            }, (res) => {
              _this.$refs.file.value = ''
              _this.progress = ''
              _this.$emit('fetchData')
            })
          })
        } else {
          params.append('infoId', this.infoId)
          params.append(`${this.prop}File`, this.$refs.file.files[0])
          _this.upLoad(updateProjectInfo, params, (res) => {
            const loaded = res.loaded
            const total = res.total
            _this.$nextTick(() => {
              _this.precent = (loaded / total) * 100
            })
          }, (res) => {
            _this.$refs.file.value = ''
            _this.progress = ''
            _this.$emit('fetchData')
          })
        }
      },
      filePathLook(row, prop) {
        const msg = {
          label: row.label,
          fileType: prop,
          infoId: row.infoId
        }
        this.$emit('openImgVisible', msg)
      }
    },
    template: `
  <el-table-column :label="colConfig.label">
            <input class="file" type="file" @change="fileChanged" ref="file"/>
            <el-table-column  v-for="(item, index) in colConfig.children"  :label="item.label" :width="item.width">
                <span slot-scope="scope" >
                    <span v-if="item.component==='filePath'">
                        <div v-if="scope.row[item.prop]">
                            <a @click="downloadFile(scope.row,item.prop,scope.column)">上传</a>
                            <a target="_blank" :href="GLOBAL.filePathUrl+ encodeURI(scope.row[item.prop])">下载</a>
                            <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.projectId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                        <div v-else>
                            <a style="color: red" >X</a>
                            <a @click="downloadFile(scope.row,item.prop,scope.column)">上传</a>
                            <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.projectId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                    </span>
                    <span v-else-if="item.component==='filePathLook'">
                        <div v-if="scope.row[item.prop]">
                            <a @click="downloadFile(scope.row,item.prop,scope.column)">上传</a>
                           <a target="_blank" @click="filePathLook(scope.row,item.prop)">查看</a>
                           <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.projectId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                        <div v-else>
                            <a style="color: red" >X</a>
                            <a @click="downloadFile(scope.row,item.prop,scope.column)">上传</a>
                            <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.projectId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                    </span>
                    <span v-else-if="item.component==='tenderFile'">
                        <div v-if="scope.row[item.prop]">
                            <a @click="downloadFile(scope.row,'letterFile',scope.column)">上传</a>
                            <a target="_blank" :href="GLOBAL.filePathUrl+ encodeURI(scope.row[item.prop])">下载</a>
                            <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.projectId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                        <div v-else>
                            <a style="color: red" >X</a>
                            <a @click="downloadFile(scope.row,'letterFile',scope.column)">上传</a>
                            <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.projectId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                    </span>
                    <span v-else-if="item.component==='contractFile'">
                        <div v-if="scope.row[item.prop]">
                            <a @click="downloadFile(scope.row,'file',scope.column)">上传</a>
                           <a target="_blank" :href="GLOBAL.filePathUrl+ encodeURI(scope.row[item.prop])">下载</a>
                           <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.projectId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                        <div v-else>
                            <a style="color: red" >X</a>
                            <a @click="downloadFile(scope.row,'file',scope.column)">上传</a>
                            <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.projectId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                    </span>
                    <span v-else>
                        <div v-if="scope.row[item.prop]">
                            <a @click="downloadFile(scope.row,item.prop+'File',scope.column)">上传</a>
                            <a target="_blank" :href="GLOBAL.filePathUrl+encodeURI(scope.row[item.prop])">下载</a>
                            <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.projectId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                        <div v-else>
                            <a style="color: red" >X</a>
                            <a @click="downloadFile(scope.row,item.prop+'File',scope.column)">上传</a>
                            <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.projectId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                    </span>
                </span>
            </el-table-column>
  </el-table-column>
  `
  }

  const professions = function(row, column) {
    if (row.professions) {
      return row.professions.split('-')[0]
    }
  }

  const isProject = function(row, column) {
    return row.isProject === 1 ? '有' : '无'
  }

  const isAdd = function(row, column) {
    if (row.isadd === null) {
      return '无'
    } else {
      return row.isAdd === 1 ? '增' : '减'
    }
  }

  const projectStage = function(row, column) {
    if (row.projectStage) {
      let obj = {}
      obj = global.projectStageList.find((item) => {
        return item.value === row.projectStage // 筛选出匹配数据
      })
      return obj.label
    }
  }

  const formatter = function(row, column) {
    if (row[column.property]) {
      let obj = {}
      obj = global[`${column.property}List`].find((item) => {
        return item.value === row[column.property] // 筛选出匹配数据
      })
      return obj.label
    }
  }

  export default {
    components: {
      myTable,
      AreaSelect
    },
    data() {
      const validPhone = (rule, value, callback) => {
        if (!value) {
          callback()
        } else if (!isvalidPhone(value)) {
          callback(new Error('请输入正确的11位手机号码'))
        } else {
          callback()
        }
      }
      return {
        colConfigs: [
          { prop: 'projectName', label: '项目名称', width: '230', fixed: true },
          { prop: 'contractCode', label: '合同编号', width: '120' },
          { prop: 'professions', label: '所属专业', width: '160', formatter: professions },
          { prop: 'teamName', label: '所属团队', width: '100' },
          { prop: 'contractAmount', label: '合同金额(万元)', width: '120' },
          { prop: 'balancePayment', label: '剩余余额(万元)', width: '120' },
          { prop: 'partyA', label: '甲方单位', width: '150' },
          { prop: 'address', label: '项目所属地', width: '150' },
          { prop: 'signDate', label: '签订日期', width: '100', component: signDate },
          { prop: 'projectLeader', label: '项目负责人', width: '100' },
          { prop: 'projectScale', label: '项目规模', width: '80' },
          { prop: 'projectCost', label: '造价(万元)', width: '80' },
          { prop: 'projectStage', label: '项目阶段', width: '80', formatter: projectStage },
          { prop: 'isProject', label: '有无项目子项目', width: '110', formatter: isProject },
          { prop: 'balance', label: '结算差额(万元)', width: '110' },
          { prop: 'isAdd', label: '形式', width: '50', formatter: isAdd },
          { prop: 'property', label: '性质', width: '80', formatter: formatter },
          { prop: 'updatePrincipal', label: '资料上传负责人', width: '120' },
          { prop: 'originalArchive', label: '原件归档处', width: '120' },
          { prop: 'leadPerson', label: '合作性质', width: '100', formatter: formatter },
          {
            label: '标前文件', width: '750', children: [
              { prop: 'tenderNotice', label: '招标公告', width: '100' },
              { prop: 'biddingDocument', label: '投标文件', width: '100' }
            ], component: configs
          },
          {
            label: '中标情况', width: '150', children: [
              { prop: 'tenderFile', label: '中标通知书', width: '100', component: 'tenderFile' }
            ], component: configs
          },
          {
            label: '合同情况', width: '150', children: [
              { prop: 'contractFile', label: '合同文件', width: '80', component: 'contractFile' }
            ], component: configs
          },
          {
            label: '方案', width: '750', children: [
              { prop: 'schemeText', label: '文本图', width: '80', component: 'filePath' },
              { prop: 'schemeCad', label: 'CAD', width: '80', component: 'filePath' },
              { prop: 'schemeRendering', label: '效果图', width: '80', component: 'filePath' },
              { prop: 'schemeProphaseData', label: '前期资料', width: '80', component: 'filePath' },
              { prop: 'schemeApprovalFile', label: '批复文件', width: '80', component: 'filePath' }
            ], component: configs
          },
          {
            label: '初步设计', width: '600', children: [
              { prop: 'designText', label: '文本图', width: '80', component: 'filePath' },
              { prop: 'designCad', label: 'CAD', width: '80', component: 'filePath' },
              { prop: 'designMinutesMeeting', label: '会议纪要', width: '80', component: 'filePath' },
              { prop: 'designApprovalFile', label: '批复文件', width: '80', component: 'filePath' }
            ], component: configs
          },
          {
            label: '施工图', width: '1200', children: [
              { prop: 'drawingReviewOpinion', label: '内部审校意见', width: '100', component: 'filePath' },
              { prop: 'drawingCad', label: 'CAD(终稿)', width: '80', component: 'filePath' },
              { prop: 'drawingDwfText', label: 'DWF文件审查合格章', width: '150', component: 'filePath' },
              { prop: 'drawingStructuralModel', label: '结构模型', width: '80', component: 'filePath' },
              { prop: 'drawingComputerBook', label: '各类计算机书', width: '100', component: 'filePath' },
              { prop: 'drawingViolationQuantity', label: '违反强条数量', width: '100', component: 'filePath' },
              { prop: 'drawingReviewCommentsResponses', label: '审查意见及回复', width: '110', component: 'filePath' },
              { prop: 'drawingReviewQualifiedBook', label: '审查合格书', width: '100', component: 'filePath' }
            ], component: configs
          },
          {
            label: '项目施工', children: [
              { prop: 'epcSubcontracting', label: 'EPC工程施工分包合同', width: '150', component: 'filePath' },
              { prop: 'epcPurchase', label: 'EPC工程材料采购合同', width: '150', component: 'filePath' },
              { prop: 'geologicalSurvey', label: '地质勘察报告', width: '100', component: 'filePath' },
              { prop: 'planLicense', label: '规划、施工许可证', width: '120', component: 'filePath' },
              { prop: 'technicalDisclosure', label: '安全、技术交底', width: '120', component: 'filePath' },
              { prop: 'startReport', label: '开工报告', width: '80', component: 'filePath' },
              { prop: 'supervision', label: '监理会议纪要', width: '100', component: 'filePath' },
              { prop: 'drawingMixed', label: '图纸会审纪要', width: '100', component: 'filePath' },
              { prop: 'constructionDesign', label: '施工组织设计', width: '100', component: 'filePath' },
              { prop: 'specialConstruction', label: '专项施工方案', width: '100', component: 'filePath' },
              { prop: 'expertArgument', label: '专家论证报告', width: '100', component: 'filePath' },
              { prop: 'levelThreeEducation', label: '人员三级教育记录', width: '120', component: 'filePath' },
              { prop: 'serviceRealName', label: '劳务实名制册', width: '100', component: 'filePath' },
              { prop: 'materialAcceptance', label: '原材料进场验收记录', width: '150', component: 'filePath' },
              { prop: 'conferences', label: '专题会议纪要', width: '100', component: 'filePath' },
              { prop: 'projectApproval', label: '工程款审批表', width: '100', component: 'filePath' },
              { prop: 'rectificationNotice', label: '整改通知回复单', width: '120', component: 'filePath' },
              { prop: 'projectNodeImage', label: '项目各节点影像资料', width: '150', component: 'filePath' },
              { prop: 'engineeringAcceptance', label: '隐蔽工程验收记录', width: '150', component: 'filePath' },
              { prop: 'rawMaterials', label: '原材料三证', width: '100', component: 'filePath' },
              { prop: 'inquiryReport', label: '无价材料询价报告', width: '150', component: 'filePath' },
              { prop: 'surveyReport', label: '测绘报告', width: '80', component: 'filePath' },
              { prop: 'siteMeasurement', label: '原始场地各方测量记录', width: '150', component: 'filePath' },
              { prop: 'mainStructureAcceptance', label: '主体结构验收报告', width: '120', component: 'filePath' },
              { prop: 'unitProjectAcceptance', label: '单位工程验收记录', width: '120', component: 'filePath' },
              { prop: 'constructionFiling', label: '施工验收备案表', width: '120', component: 'filePath' },
              { prop: 'engineeringDelay', label: '工程延误报告', width: '100', component: 'filePath' },
              { prop: 'engineeringQuality', label: '工程质量保修书', width: '120', component: 'filePath' },
              { prop: 'completionMap', label: '竣工图', width: '80', component: 'filePath' },
              { prop: 'projectFinalAccount', label: '工程决算书', width: '100', component: 'filePath' },
              { prop: 'auditReport', label: '审计报告', width: '80', component: 'filePath' }
            ], component: configs
          },
          {
            label: '竣工', width: '150', children: [
              { prop: 'completionAcceptanceReport', label: '验收报告', width: '80', component: 'filePathLook' }
            ], component: configs
          },
          { slot: 'opt' }
        ],
        /*
        scheduleConfigs: [
          { prop: 'schemeText', label: '方案文本图', width: '150', component: filePath },
          { prop: 'schemeCad', label: '方案CAD', width: '150', component: filePath },
          { prop: 'schemeRendering', label: '方案效果图', width: '150', component: filePath },
          { prop: 'schemeProphaseData', label: '前期资料', width: '150', component: filePath },
          { prop: 'schemeApprovalFile', label: '方案批复文件', width: '150', component: filePath },
          { prop: 'designText', label: '初步设计文本图', width: '150', component: filePath },
          { prop: 'designCad', label: '初步设计CAD', width: '150', component: filePath },
          { prop: 'designMinutesMeeting', label: '会议纪要', width: '150', component: filePath },
          { prop: 'designApprovalFile', label: '初步设计批复文件', width: '150', component: filePath },
          { prop: 'drawingReviewOpinion', label: '内部审校意见', width: '150', component: filePath },
          { prop: 'drawingCad', label: 'CAD(终稿)', width: '150', component: filePath },
          { prop: 'drawingDwfText', label: 'DWF文件审查合格章', width: '150', component: filePath },
          { prop: 'drawingStructuralModel', label: '结构模型', width: '150', component: filePath },
          { prop: 'drawingComputerBook', label: '各类计算机书', width: '150', component: filePath },
          { prop: 'drawingViolationQuantity', label: '违反强条数量', width: '150', component: filePath },
          { prop: 'drawingReviewCommentsResponses', label: '审查意见及回复', width: '150', component: filePath },
          { prop: 'drawingReviewQualifiedBook', label: '审查合格书', width: '150', component: filePath },
          { prop: 'completionAcceptanceReport', label: '验收报告', width: '150', component: filePath },
          { slot: 'scheduleOpt' }
        ],
        */
        roleTypeConfigs: [
          { prop: 'projectName', label: '项目名称', width: '230', fixed: true },
          { prop: 'contractCode', label: '合同编号', width: '120' },
          { prop: 'professions', label: '所属专业', width: '160', formatter: professions },
          { prop: 'teamName', label: '所属团队', width: '100' },
          { prop: 'contractAmount', label: '合同金额(万元)', width: '120' },
          { prop: 'balancePayment', label: '剩余余额(万元)', width: '120' },
          { prop: 'partyA', label: '甲方单位', width: '150' },
          { prop: 'address', label: '项目所属地', width: '150' },
          { prop: 'signDate', label: '签订日期', width: '100', component: signDate },
          { prop: 'projectLeader', label: '项目负责人', width: '100' },
          { prop: 'projectScale', label: '项目规模', width: '80' },
          { prop: 'projectCost', label: '造价(万元)', width: '80' },
          { prop: 'projectStage', label: '项目阶段', width: '80', formatter: projectStage },
          { prop: 'isProject', label: '有无项目子项目', width: '110', formatter: isProject },
          { prop: 'balance', label: '结算差额(万元)', width: '110' },
          { prop: 'isAdd', label: '形式', width: '50', formatter: isAdd },
          {
            label: '中标情况', width: '150', children: [
              { prop: 'tenderFile', label: '中标通知书', width: '100', component: 'tenderFile' }
            ], component: configs
          },
          {
            label: '合同情况', width: '150', children: [
              { prop: 'contractFile', label: '合同文件', width: '80', component: 'contractFile' }
            ], component: configs
          },
          {
            label: '施工图', width: '1200', children: [
              { prop: 'drawingViolationQuantity', label: '违反强条数量', width: '100', component: 'filePath' },
              { prop: 'drawingReviewCommentsResponses', label: '审查意见及回复', width: '110', component: 'filePath' },
              { prop: 'drawingReviewQualifiedBook', label: '审查合格书', width: '100', component: 'filePath' }
            ], component: configs
          },
          { slot: 'opt' }
        ],
        imgConfigs: [
          { prop: 'fileName', label: '文件名称', width: '135' },
          { prop: 'filePath', label: '文件', width: '135', component: filePath },
          { prop: 'dateCreated', label: '上传时间', width: '135', component: signDate },
          { slot: 'imgOpt' }
        ],
        searchForm: {},
        dialogForm: {},
        searchFormList: {},
        dialogFormList: {},
        infoTypeList: [],
        parentProfessionList: [],
        professionList: [],
        parentList: [],
        listLoading: true,
        scheduleLoading: true,
        dialogTitle: '新增合同项目',
        scheduleTitle: '项目资料管理',
        scheduleType: 1,
        scheduleBtn: '添加资料',
        dialogType: 0,
        teamRow: {
          childProfessions: [],
          parentProfessions: [],
          isProject: 0,
          property: 1
        },
        teamRowClear: {
          childProfessions: [],
          parentProfessions: [],
          isProject: 0,
          property: 1
        },
        schedule: {
          phase: 1
        },
        scheduleClear: {
          phase: 1
        },
        tableData: [],
        scheduleData: [],
        pageNum: 1,
        pageSize: 10,
        total: 1,
        outerVisible: false,
        scheduleVisible: false,
        professionVisible: false,
        isAddress: true, // 地区新增 修改 摧毁 生成组件
        isRender: false, // 判断地区是否编辑
        pca: pca,
        rules: {
          projectName: [
            { required: true, message: '请输入项目名称', trigger: 'change' }
          ],
          teamName: [
            { required: true, message: '请输入团队', trigger: 'change' }
          ],
          contractCode: [
            { required: true, message: '请输入合同编号', trigger: 'change' }
          ]
          // leadingDiscipline: [
          //   { required: true, message: '请选择主导专业', trigger: 'change' }
          // ]
          /*
          partyA: [
            { required: true, message: '请输入甲方单位', trigger: 'change' }
          ],
          address: [
            { required: true, message: '请输入项目所属地', trigger: 'change' }
          ],
          signDate: [
            { required: true, message: '请选择签订日期', trigger: 'change' }
          ],
          projectScale: [
            { required: true, message: '请输入项目规模', trigger: 'change' }
          ],
          contractAmount: [
            { required: true, message: '请输入合同金额', trigger: 'change' }
          ],
          projectStage: [
            { required: true, message: '请选择项目阶段', trigger: 'change' }
          ],
          balance: [
            { required: true, message: '请输入结算差额', trigger: 'change' }
          ],
          isAdd: [
            { required: true, message: '请选择形式', trigger: 'change' }
          ],
          professions: [
            { required: true, message: '请选择所属专业', trigger: 'change' }
          ],
          principalContact: [
            { required: false, trigger: 'change', validator: validPhone }
          ]
          */
        },
        scheduleRules: {
          projectName: [
            { required: true, message: '请输入项目名称', trigger: 'change' }
          ],
          infoTitle: [
            { required: true, message: '请输入资料名称', trigger: 'change' }
          ],
          infoTypeId: [
            { required: true, message: '请选择资料类型', trigger: 'change' }
          ]
        },
        visible: false,
        pp: [],
        isProjectDisabled: false,
        isContractCode: false,
        tableType: true, // 可以开启展开行功能
        expandAll: false, // 表格展开折叠
        exportUrl: '', // 导出参数
        imgVisible: false,
        imgTableVisible: false,
        imgMsg: {},
        imgTableData: [],
        imgListLoading: false,
        imgTableParams: {}
      }
    },
    created() {
      this.teamRowClear = JSON.parse(JSON.stringify(this.teamRow))
      this.fetchData()
      this.getParentProfessionList()
      this.getListProfession()
      // this.getTypeByUseType()
    },
    computed: {
      global() {
        return global
      },
      teamId() {
        return this.$store.state.user.teamId
      },
      teamName() {
        return this.$store.state.user.teamName
      },
      isDirector() {
        return this.$store.state.user.isDirector
      },
      roleType() {
        return this.$store.state.user.roleType
      }
    },
    methods: {
      fetchData() {
        this.searchFormList.pageNum = this.pageNum
        this.searchFormList.pageSize = this.pageSize
        this.searchFormList.isDirector = this.isDirector
        this.searchFormList.teamId = this.teamId
        this.listLoading = true
        getListProject(this.searchFormList).then(response => {
          this.tableData = response.responseBody.list
          this.total = response.responseBody.total
          this.listLoading = false
        })
      },
      getParentProfessionList() {
        getParentProfessionList().then(response => {
          this.parentProfessionList = response.responseBody
        })
      },
      getListProfession() {
        selectProfessions().then(response => {
          const that = this
          this.professionList = response.responseBody
          this.professionList.forEach(function(value, index, array) {
            that.parentList[index] = []
            value.getParent.forEach(function(value) {
              that.parentList[index].push(value.professionId)
            })
          })
        })
      },
      scheduleFetchData() {
        this.fileClear()
        this.scheduleLoading = true
        this.dialogFormList.projectId = this.schedule.projectId
        getProjectInfoList(this.dialogFormList).then(response => {
          console.log(response.responseBody)
          this.scheduleData = response.responseBody
          this.schedule = Object.assign({}, this.schedule, response.responseBody[0])
          this.scheduleLoading = false
        })
      },
      getTypeByUseType() {
        const params = {
          useType: 3
        }
        getTypeByUseType(params).then(response => {
          this.infoTypeList = response.responseBody
        })
      },
      provinceChange() {
        this.searchForm.cityId = ''
      },
      cityChange() {
        console.log(this.pca[this.searchForm.provinceId])
      },
      search() {
        this.pageNum = 1
        this.searchFormList = JSON.parse(JSON.stringify(this.searchForm))
        this.fetchData()
      },
      // searchDialogForm() {
      //   this.dialogFormList = JSON.parse(JSON.stringify(this.dialogForm))
      //   this.scheduleFetchData()
      // },
      addTeam() {
        this.outerVisible = true
        this.isAddress = true
        this.isProjectDisabled = false
        this.isContractCode = false
        this.dialogTitle = '新增合同项目'
        this.teamRow = JSON.parse(JSON.stringify(this.teamRowClear))
        this.pp = []
        if (this.$refs['teamRow']) {
          this.$refs['teamRow'].resetFields()
        }
        this.dialogType = 1
        if (this.$refs.letterFile) {
          this.$refs.letterFile.value = ''
        }
        if (this.$refs.contractFile) {
          this.$refs.contractFile.value = ''
        }
        if (this.$refs.tenderNoticeFile) {
          this.$refs.tenderNoticeFile.value = ''
        }
        if (this.$refs.biddingDocumentFile) {
          this.$refs.biddingDocumentFile.value = ''
        }
        this.$set(this.teamRow, 'invoiceRate', 9)
        this.$set(this.teamRow, 'projectRate', 0)
        this.$set(this.teamRow, 'epcRate', 0)
        this.$set(this.teamRow, 'teamId', this.teamId)
        this.$set(this.teamRow, 'teamName', this.teamName)
      },
      editTeam(projectId) {
        if (this.$refs['teamRow']) {
          this.$refs['teamRow'].resetFields()
        }
        this.outerVisible = true
        this.isAddress = true
        this.isRender = true
        this.isProjectDisabled = false
        this.isContractCode = false
        this.dialogTitle = '修改合同项目'
        this.dialogType = 0
        if (this.$refs.letterFile) {
          this.$refs.letterFile.value = ''
        }
        if (this.$refs.contractFile) {
          this.$refs.contractFile.value = ''
        }
        if (this.$refs.tenderNoticeFile) {
          this.$refs.tenderNoticeFile.value = ''
        }
        if (this.$refs.biddingDocumentFile) {
          this.$refs.biddingDocumentFile.value = ''
        }
        this.teamRow = JSON.parse(JSON.stringify(this.teamRowClear))
        this.pp = []
        const params = {
          projectId: projectId
        }
        findProjectById(params).then(response => {
          const data = response.responseBody
          this.teamRow = Object.assign({}, this.teamRow, data)
          if (data.professions !== '-') {
            const professions = data.professions.split('-')
            this.teamRow.parentProfessions = professions[0].split(',')
            const childProfessions = professions[1].split(',')
            childProfessions.forEach(value => {
              this.teamRow.childProfessions.push(parseInt(value))
            })
          } else {
            this.teamRow.parentProfessions = []
            this.teamRow.childProfessions = []
          }
          if (this.teamRow.provinceId && this.teamRow.cityId) {
            this.teamRow.addressId = [this.teamRow.provinceId.toString(), this.teamRow.cityId.toString()]
          }
          this.teamRow.pp.forEach(value => {
            this.pp.push({
              price: value.price,
              percentage: value.percentage,
              node: value.node
            })
          })
          if (this.teamRow.isProject) {
            this.isProjectDisabled = true
          }
        })
      },
      closeOuterVisible() {
        this.isAddress = false
      },
      submitForm(formName) {
        const params = new FormData()
        if (!this.dialogType) {
          params.append('projectId', this.teamRow.projectId)
        }
        params.append('projectName', this.teamRow.projectName)
        params.append('teamId', this.teamRow.teamId)
        params.append('contractCode', this.teamRow.contractCode)
        params.append('partyA', this.teamRow.partyA || '')
        params.append('property', this.teamRow.property)
        params.append('provinceId', this.teamRow.provinceId || '')
        params.append('cityId', this.teamRow.cityId || '')
        params.append('address', this.teamRow.address || '')
        params.append('projectLeader', this.teamRow.projectLeader || '')
        params.append('principalContact', this.teamRow.principalContact || '')
        if (this.teamRow.signDate) {
          params.append('signDate', this.teamRow.signDate)
        }
        params.append('projectScale', this.teamRow.projectScale || '')
        params.append('contractAmount', this.teamRow.contractAmount || 0)
        params.append('projectStage', this.teamRow.projectStage || '')
        params.append('projectCost', this.teamRow.projectCost || 0)
        params.append('letterFile', this.teamRow.letterFile)
        const professions = this.teamRow.parentProfessions.join(',') + '-' + this.teamRow.childProfessions.join(',')
        params.append('professions', professions)
        params.append('leadingDiscipline', this.teamRow.leadingDiscipline || '')
        params.append('isProject', this.teamRow.isProject)
        params.append('pp', JSON.stringify(this.pp))
        if (this.teamRow.file) {
          params.append('file', this.teamRow.file)
        }
        if (this.teamRow.isProject) {
          params.append('balance', this.teamRow.balance)
          params.append('isAdd', this.teamRow.isAdd)
          params.append('childRemark', this.teamRow.childRemark || '')
        }
        params.append('invoiceRate', this.teamRow.invoiceRate || 0)
        params.append('projectRate', this.teamRow.projectRate || 0)
        params.append('epcRate', this.teamRow.epcRate || 0)
        params.append('managementFee', this.teamRow.managementFee || 0)
        params.append('signature', this.teamRow.signature || 0)
        params.append('audit', this.teamRow.audit || 0)
        params.append('other', this.teamRow.other || 0)
        params.append('remark', this.teamRow.remark || '')
        params.append('updatePrincipal', this.teamRow.updatePrincipal || '')
        params.append('originalArchive', this.teamRow.originalArchive || '')
        params.append('leadPerson', this.teamRow.leadPerson || '')
        if (this.teamRow.tenderNoticeFile) {
          params.append('tenderNoticeFile', this.teamRow.tenderNoticeFile)
        }
        if (this.teamRow.biddingDocumentFile) {
          params.append('biddingDocumentFile', this.teamRow.biddingDocumentFile)
        }
        if (this.teamRow.teamId) {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              if (this.dialogType) {
                addProject1(params).then(response => {
                  addProject(params).then(response => {
                    this.outerVisible = false
                    this.isAddress = false
                    this.fetchData()
                  })
                })
              } else {
                updateProject1(params).then(response => {
                  updateProject(params).then(response => {
                    this.outerVisible = false
                    this.isAddress = false
                    this.fetchData()
                  })
                })
              }
            } else {
              console.log('error submit!!')
              return false
            }
          })
        } else {
          this.$message({
            message: '该团队不存在',
            type: 'warning'
          })
        }
      },
      deleteRow(scope) {
        this.$refs[`popover-${scope.$index}`].doClose()
        const params = new FormData()
        params.append('projectId', scope.row.projectId)
        params.append('isDel', 1)
        updateProject(params).then(response => {
          this.fetchData()
        })
      },
      editSchedule(row) {
        this.scheduleVisible = true
        this.scheduleClear.projectId = row.projectId
        this.scheduleClear.projectName = row.projectName
        this.schedule = JSON.parse(JSON.stringify(this.scheduleClear))
        this.scheduleFetchData()
        // this.scheduleType = 1
        this.fileClear()
      },
      submitSchedule(scheduleName) {
        const params = new FormData()
        params.append('infoId', this.schedule.infoId)
        params.append('projectId', this.schedule.projectId)
        params.append('remark', this.schedule.remark || '')
        if (this.schedule.phase === 1) {
          if (this.schedule.schemeTextFile) {
            params.append('schemeTextFile', this.schedule.schemeTextFile)
          }
          if (this.schedule.schemeCadFile) {
            params.append('schemeCadFile', this.schedule.schemeCadFile)
          }
          if (this.schedule.schemeRenderingFile) {
            params.append('schemeRenderingFile', this.schedule.schemeRenderingFile)
          }
          if (this.schedule.schemeProphaseDataFile) {
            params.append('schemeProphaseDataFile', this.schedule.schemeProphaseDataFile)
          }
          if (this.schedule.schemeApprovalFileFile) {
            params.append('schemeApprovalFileFile', this.schedule.schemeApprovalFileFile)
          }
        } else if (this.schedule.phase === 2) {
          if (this.schedule.designTextFile) {
            params.append('designTextFile', this.schedule.designTextFile)
          }
          if (this.schedule.designCadFile) {
            params.append('designCadFile', this.schedule.designCadFile)
          }
          if (this.schedule.designMinutesMeetingFile) {
            params.append('designMinutesMeetingFile', this.schedule.designMinutesMeetingFile)
          }
          if (this.schedule.designApprovalFileFile) {
            params.append('designApprovalFileFile', this.schedule.designApprovalFileFile)
          }
        } else if (this.schedule.phase === 3) {
          if (this.schedule.drawingReviewOpinionFile) {
            params.append('drawingReviewOpinionFile', this.schedule.drawingReviewOpinionFile)
          }
          if (this.schedule.drawingCadFile) {
            params.append('drawingCadFile', this.schedule.drawingCadFile)
          }
          if (this.schedule.drawingDwfTextFile) {
            params.append('drawingDwfTextFile', this.schedule.drawingDwfTextFile)
          }
          if (this.schedule.drawingStructuralModelFile) {
            params.append('drawingStructuralModelFile', this.schedule.drawingStructuralModelFile)
          }
          if (this.schedule.drawingComputerBookFile) {
            params.append('drawingComputerBookFile', this.schedule.drawingComputerBookFile)
          }
          if (this.schedule.drawingViolationQuantityFile) {
            params.append('drawingViolationQuantityFile', this.schedule.drawingViolationQuantityFile)
          }
          if (this.schedule.drawingReviewCommentsResponsesFile) {
            params.append('drawingReviewCommentsResponsesFile', this.schedule.drawingReviewCommentsResponsesFile)
          }
          if (this.schedule.drawingReviewQualifiedBookFile) {
            params.append('drawingReviewQualifiedBookFile', this.schedule.drawingReviewQualifiedBookFile)
          }
        } else {
          if (this.schedule.completionAcceptanceReportFile) {
            params.append('completionAcceptanceReportFile', this.schedule.completionAcceptanceReportFile)
          }
        }
        this.$refs[scheduleName].validate((valid) => {
          if (valid) {
            updateProjectInfo(params).then(response => {
              this.scheduleFetchData()
              this.schedule = JSON.parse(JSON.stringify(this.scheduleClear))
            })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      deleteSchedule(scope) {
        this.$refs[`schedule-${scope.$index}`].doClose()
        const params = new FormData()
        params.append('infoId', scope.row.infoId)
        params.append('isDel', 1)
        updateProjectInfo(params).then(response => {
          this.scheduleFetchData()
        })
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.pageNum = val
        this.fetchData()
      },
      addressChange() {
        this.teamRow.provinceId = parseInt(this.teamRow.addressId[0])
        this.teamRow.cityId = parseInt(this.teamRow.addressId[1])
        if (!this.isRender) {
          this.teamRow.address = this.pca[86][this.teamRow.addressId[0]] + this.pca[this.teamRow.addressId[0]][this.teamRow.addressId[1]]
        } else {
          this.isRender = false
        }
      },
      handleprofessionChange(index, profession) {
        const parentList = this.parentList[index]
        let isIndex = 1
        for (let i = 0; i < parentList.length; i++) {
          console.log(parentList[i])
          if (this.teamRow.childProfessions.indexOf(parentList[i]) !== -1) {
            isIndex = 1
            break
          } else {
            isIndex = 0
          }
        }
        if (isIndex) {
          this.teamRow.parentProfessions.push(profession.professionName)
          this.teamRow.parentProfessions = [...new Set(this.teamRow.parentProfessions)]
        } else {
          this.teamRow.parentProfessions.splice(this.teamRow.parentProfessions.findIndex(item => item === profession.professionName), 1)
        }
      },
      querySearchProject(queryString, callback) {
        // queryString 为在框中输入的值
        // callback 回调函数,将处理好的数据推回
        if (queryString) {
          const params = {
            projectName: queryString
          }
          selectTeam(params).then(response => {
            for (const i of response.responseBody) {
              i.value = i.projectName
            }
            let teamList = response.responseBody
            if (teamList.length === 0) {
              teamList = [{ value: '暂无数据' }]
            }
            callback(teamList)
          })
        } else {
          callback([])
        }
      },
      handleSelectProject(item) {
        this.$set(this.teamRow, 'projectId', item.projectId)
      },
      querySearchTeam(queryString, callback) {
        // queryString 为在框中输入的值
        // callback 回调函数,将处理好的数据推回
        delete this.teamRow.teamId
        if (queryString) {
          const params = {
            teamName: queryString
          }
          selectTeam(params).then(response => {
            for (const i of response.responseBody) {
              i.value = i.teamName
            }
            let nameList = response.responseBody
            if (nameList.length === 0) {
              nameList = [{ value: '暂无数据' }]
            }
            callback(nameList)
          })
        } else {
          callback([])
        }
      },
      handleSelectTeam(item) {
        this.$set(this.teamRow, 'teamId', item.teamId)
        this.$set(this.teamRow, 'teamName', item.teamName)
        this.$set(this.teamRow, 'managementFee', item.managementFeeRate)
      },
      fileClear() {
        if (this.$refs.schemeText) {
          this.$refs.schemeText.value = ''
        }
        if (this.$refs.schemeCad) {
          this.$refs.schemeCad.value = ''
        }
        if (this.$refs.schemeRendering) {
          this.$refs.schemeRendering.value = ''
        }
        if (this.$refs.schemeProphaseData) {
          this.$refs.schemeProphaseData.value = ''
        }
        if (this.$refs.schemeApprovalFile) {
          this.$refs.schemeApprovalFile.value = ''
        }
        if (this.$refs.designText) {
          this.$refs.designText.value = ''
        }
        if (this.$refs.designCad) {
          this.$refs.designCad.value = ''
        }
        if (this.$refs.designMinutesMeeting) {
          this.$refs.designMinutesMeeting.value = ''
        }
        if (this.$refs.designApprovalFile) {
          this.$refs.designApprovalFile.value = ''
        }
        if (this.$refs.drawingReviewOpinion) {
          this.$refs.drawingReviewOpinion.value = ''
        }
        if (this.$refs.drawingCad) {
          this.$refs.drawingCad.value = ''
        }
        if (this.$refs.drawingDwfText) {
          this.$refs.drawingDwfText.value = ''
        }
        if (this.$refs.drawingStructuralModel) {
          this.$refs.drawingStructuralModel.value = ''
        }
        if (this.$refs.drawingComputerBook) {
          this.$refs.drawingComputerBook.value = ''
        }
        if (this.$refs.drawingViolationQuantity) {
          this.$refs.drawingViolationQuantity.value = ''
        }
        if (this.$refs.drawingReviewCommentsResponses) {
          this.$refs.drawingReviewCommentsResponses.value = ''
        }
        if (this.$refs.drawingReviewQualifiedBook) {
          this.$refs.drawingReviewQualifiedBook.value = ''
        }
        if (this.$refs.completionAcceptanceReport) {
          this.$refs.completionAcceptanceReport.value = ''
        }
      },
      getFile(event) {
        this.teamRow.file = event.target.files[0]
      },
      getLetterFile(event) {
        this.teamRow.letterFile = event.target.files[0]
      },
      getTenderNoticeFile(event) {
        this.teamRow.tenderNoticeFile = event.target.files[0]
      },
      getBiddingDocumentFile(event) {
        this.teamRow.biddingDocumentFile = event.target.files[0]
      },
      fileUpload(event, scheduleName) {
        this.$set(this.schedule, scheduleName, event.target.files[0])
      },
      editProfession(professions) {
        this.professionVisible = true
        this.teamRow.parentProfessions = []
        this.teamRow.childProfessions = []
        this.teamRow.parentProfessions = professions.split('-')[0].split(',')
        const childProfessions = professions.split('-')[1].split(',')
        childProfessions.forEach(value => {
          this.teamRow.childProfessions.push(parseInt(value))
        })
      },
      addpp() {
        this.pp.push({
          price: 0,
          percentage: 0,
          node: ''
        })
      },
      delpp(index) {
        this.pp.splice(index, 1)
        console.log(this.teamRow)
      },
      percentageChange(item, index) {
        const price = item.percentage / 100 * this.teamRow.contractAmount || 0
        this.pp[index].price = Math.round(price * 100) / 100
      },
      contractBlur() {
        if (this.dialogType === 1) {
          const params = new FormData()
          params.append('contractCode', this.teamRow.contractCode)
          findRepeatProject(params).then(response => {
            if (response.resultCode === 1) {
              this.isContractCode = false
            } else {
              this.isContractCode = true
            }
          })
        }
      },
      initImgTable() {
        this.imgListLoading = true
        getAttachList(this.imgTableParams).then(response => {
          this.imgTableData = response.responseBody
          this.imgListLoading = false
        })
      },
      openVisible(msg) {
        this.msg = msg
        this.imgTableVisible = true
        this.imgTableParams = {
          infoId: msg.infoId,
          fileType: msg.fileType
        }
        this.initImgTable()
      },
      deleteImgTable(scope) {
        this.$refs[`popover-imgTable${scope.$index}`].doClose()
        const params = new FormData()
        params.append('attachId', scope.row.attachId)
        delAttach(params).then(response => {
          this.initImgTable()
        })
      }
    },
    mounted() {
    },
    watch: {
      'teamRow.contractAmount': {
        handler(newValue, oldValue) {
          this.pp.forEach(value => {
            value.price = Math.round(value.percentage / 100 * newValue * 100) / 100
          })
        },
        immediate: true
      },
      'searchForm': {
        handler(newValue, oldValue) {
          let exportUrl = ''
          this.searchForm.isDirector = this.isDirector
          this.searchForm.teamId = this.teamId
          Object.keys(this.searchForm).map((key) => {
            exportUrl += key + '=' + this.searchForm[key] + '&'
          })
          this.exportUrl = exportUrl
        },
        immediate: true,
        deep: true // 深度监听
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss">
  .app-container {
    .el-pagination {
      margin-top: 20px;
    }

    .table-btn {
      margin-bottom: 10px;

      & > button {
        margin: 0 20px;
      }

      .el-dialog {
        textarea {
          margin-top: 10px;
        }

        .el-checkbox {
          margin-right: 20px;
        }

        .el-checkbox + .el-checkbox {
          margin-left: 0;
        }

        .item-inline {
          display: inline-block;
        }
      }
    }

    .file {
      display: none;
    }
  }
</style>


<style rel="stylesheet/scss" lang="scss">
  .el-table__expanded-cell[class*=cell] {
    padding: 5px 50px 0;
    font-size: 10px;
  }

  .el-input__icon {
    line-height: 100%;
  }

  .el-form-item__content {
    line-height: 33px;
  }

  .area-select .area-selected-trigger {
    padding: 0 10px;
  }

  .el-input--suffix .el-input__inner {
    padding-right: 15px;
  }

  a, a:focus, a:hover {
    color: #409EFF;
  }

  /*.el-table__body tr.hover-row>td {
    background-color: #0000ff !important;
  }

  .el-table__body tr.current-row>td {
    background-color: #0000ff !important;
  }*/
</style>
